<template>
  <view>
    <u-gap height="8"></u-gap>
    <view class="bg-white">
      <view class="padding-lg">
        <view class="title">企业公告</view>
        <view class="text">
          {{notice}}
        </view>
        <!-- <view class="date">2019-01-15 14:34:23</view> -->
      </view>

      <view class="padding" v-if="auth">
        <my-btn width="370" @click="popShow = true">编辑公告</my-btn>
      </view>

      <u-popup v-model="popShow" mode="center" border-radius="16">
        <view class="padding">
          <textarea class="edit" v-model="editNotice" placeholder="" />
          <view class="padding-top">
            <my-btn width="370" @click="submit">发布更新</my-btn>
          </view>
        </view>
      </u-popup>
    </view>

    <view class="padding-lg">
      <view class="title">企业动态</view>
      <view class="tip" v-for="i in dynamic" :key="i.id">
        <view class="text">{{i.desc}}</view>
        <view class="date">{{i.time}}</view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        id: '',
        auth: false,
        notice: '...',
        editNotice: '',
        dynamic: [],
        popShow: false
      };
    },
    onLoad(opt) {
      this.id = opt.id
      this.getList()
    },
    methods: {
      async getList() {
        let res = await this.$u.get('/company/dynamic?id=' + this.id)
        let {
          auth,
          notice,
          dynamic
        } = res.data.result
        this.auth = auth
        this.notice = notice
        this.editNotice = notice
        this.dynamic = dynamic
      },
      async submit() {
        this.popShow = false
        let params = {
          id: this.id,
          notice: this.editNotice
        }
        let res = await this.$u.post('/company/notice/edit', params)
        let { msg, result } = res.data
        this.$msg(msg)
        this.getList()
      }
    }
  }
</script>

<style lang="scss">
  .title {
    font-size: 32rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: #313131;
  }

  .text {
    font-size: 26rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #787878;
    margin: 16rpx 0;
  }
  
  .edit {
    padding: 16rpx;
    border-radius: 8rpx;
    border: 1px solid rgba(0,0,0,0.1);
  }

  .date {
    font-size: 22rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #B4B7BE;
  }

  .tip {
    padding-top: 16rpx;
    margin-left: 24rpx;
    position: relative;

    &::before {
      content: '';
      width: 10rpx;
      height: 10rpx;
      background: #B4B7BE;
      border-radius: 50%;
      position: absolute;
      top: 44rpx;
      left: -20rpx;
    }
  }
</style>
